﻿Imports System.Collections.Generic
Imports System.Data.SqlClient
Namespace QuanLyKhachHang
    Public Class ThongKeSanLuongDAL
        Public Function ThongKeSanLuong_LoaiSanPham(ByVal TrangThai As String, ByVal TuNgay As Integer, ByVal DenNgay As Integer, ByVal KhachHangId As Integer, ByVal MaTinhThanh As Integer) As List(Of LoaiSanPham)
            Try
                Dim SQLHelper As New SQLDataHelper
                Dim Reader As SqlDataReader
                SQLHelper.AddParameter("@TrangThai", TrangThai)
                SQLHelper.AddParameter("@TuNgay", TuNgay)
                SQLHelper.AddParameter("@DenNgay", DenNgay)
                SQLHelper.AddParameter("@KhachHangId", KhachHangId)
                SQLHelper.AddParameter("@MaTinhThanh", MaTinhThanh)
                Reader = SQLHelper.ExecuteReader("sp_ThongKeSanLuong_LoaiSanPham", CommandType.StoredProcedure)
                Dim item As LoaiSanPham
                Dim list As New List(Of LoaiSanPham)
                While (Reader.Read())
                    item = New LoaiSanPham
                    item.IDLoai = Integer.Parse(Reader("IDLoai").ToString())
                    item.TenLoai = Reader("TenLoai").ToString()
                    list.Add(item)
                End While
                Return list
            Catch ex As Exception
                Throw ex
            End Try
        End Function

        Public Function ThongKeSanLuong_SanPham(ByVal TrangThai As String, ByVal TuNgay As Integer, ByVal DenNgay As Integer, ByVal IDLoai As Integer, ByVal KhachHangId As Integer, ByVal MaTinhThanh As Integer) As List(Of SanPham)
            Try
                Dim SQLHelper As New SQLDataHelper
                Dim Reader As SqlDataReader
                SQLHelper.AddParameter("@TrangThai", TrangThai)
                SQLHelper.AddParameter("@TuNgay", TuNgay)
                SQLHelper.AddParameter("@DenNgay", DenNgay)
                SQLHelper.AddParameter("@IDLoai", IDLoai)
                SQLHelper.AddParameter("@KhachHangId", KhachHangId)
                SQLHelper.AddParameter("@MaTinhThanh", MaTinhThanh)
                Reader = SQLHelper.ExecuteReader("sp_ThongKeSanLuong_SanPham", CommandType.StoredProcedure)
                Dim item As SanPham
                Dim list As New List(Of SanPham)
                While (Reader.Read())
                    item = New SanPham
                    item.IDSanPham = Integer.Parse(Reader("IDSanPham").ToString())
                    item.MaSanPham = Reader("MaSanPham").ToString()
                    item.TenSanPham = Reader("TenSanPham").ToString()
                    item.TenDonVi = Reader("TenDonVi").ToString()
                    item.SoLuongTheoQuyCach = Single.Parse(Reader("SoLuongTheoQuyCach").ToString())
                    list.Add(item)
                End While
                Return list
            Catch ex As Exception
                Throw ex
            End Try
        End Function
        Public Function ThongKeSanLuong_TieuThu(ByVal TrangThai As String, ByVal TuNgay As Integer, ByVal DenNgay As Integer, ByVal IDSanPham As Integer, ByVal KhachHangId As Integer, ByVal MaTinhThanh As Integer) As Single
            Try
                Dim SQLHelper As New SQLDataHelper
                SQLHelper.AddParameter("@TrangThai", TrangThai)
                SQLHelper.AddParameter("@TuNgay", TuNgay)
                SQLHelper.AddParameter("@DenNgay", DenNgay)
                SQLHelper.AddParameter("@IDSanPham", IDSanPham)
                SQLHelper.AddParameter("@KhachHangId", KhachHangId)
                SQLHelper.AddParameter("@MaTinhThanh", MaTinhThanh)
                Return Single.Parse(SQLHelper.ExecuteScalar("sp_ThongKeSanLuong_TieuThu", CommandType.StoredProcedure))
            Catch ex As Exception
                Throw ex
            End Try
        End Function
    End Class
End Namespace
